class Queue:
    def __init__(self):
        self.items = []

    def isEmpty(self):
        return self.items == []

    def enqueue(self, item):
        self.items.insert(0,item)

    def dequeue(self):
        return self.items.pop()

    def size(self):
        return len(self.items)
mp=[]
h,w=0,0
dir=[(0,-1),(-1,0),(0,1),(1,0)]

def bfs(r,c):
    global mp,h,w,dir
    q=Queue()
    q.enqueue((r,c))
    mp[r][c]='0'
    while not q.isEmpty():
        pt=q.dequeue();
        for i in range(4):
            nr=pt[0]+dir[i][0]
            nc=pt[1]+dir[i][1]
            if 0<=nr<h and 0<=nc<w and mp[nr][nc]!='0':
                q.enqueue((nr,nc))
                mp[nr][nc]='0'
h,w=map(int,input().split())
for i in range(h):
    row=list(input())
    mp.append(row)
num=0
for i in range(h):
    for j in range(w):
        if mp[i][j]!='0':
            num+=1
            bfs(i,j)
print(num)